﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 自定义年月日期选择
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 监听日历模式切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void calendar_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e)
        {
            if (calendar.DisplayMode==CalendarMode.Month || calendar.DisplayMode==CalendarMode.Decade)
            {
                calendar.DisplayMode = CalendarMode.Year;
            }
        }
        /// <summary>
        /// 点击日历图标显示Calendar控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tb_calendar_img_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (Pop.IsOpen)
            {
                Pop.IsOpen = false;
            }
            else
            {
                Pop.IsOpen = true;
            }
        }
        /// <summary>
        /// 监听日期变化，隐藏Calendar控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void calendar_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e)
        {
            var year = calendar.DisplayDate.Date.Year;
            var month = calendar.DisplayDate.Date.Month;
            tb_calendar.Text = year + "年" + month+"月";
            Pop.IsOpen = false;
        }
    }
}
